#include <stdio.h>
#include <stdlib.h>

int diag1[100], diag2[100], col[100];

int n;

int s[100];
int sol;

bool check(int i) 
{
  return (!diag1[i+s[i]] && !diag2[i-s[i]+n] && !col[s[i]]);
}

void solve(int i) 
{
  //printf("i:%d", i);
  if (i>=n) {
    sol++;
    printf("no. %d: ", sol);
    for (int j=0; j<n; j++)
      printf("%d ", s[j]);
  }
  else {
    for (int j=0; j<n; j++) {
      s[i] = j;
      if (check(i)) {
	diag1[i+j] = 1;
	diag2[i-j+n] = 1;
	col[j] = 1;
	solve(i+1);
	diag1[i+j] = 0;
	diag2[i-j+n] = 0;
	col[j] = 0;
      }
    }
  }
}


int main() 
{
  n = 8;
  solve(0);
  return 0;
}

